<template>
  <el-dialog
      :title="'请填写'+model.name+'表'"
      :visible.sync="dialogVisible"
      width="70%"
      append-to-body
      :show-close="false"
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      :close-on-click-modal="false"
      @close="handleClose">
    <start-activiti-component
        ref="startActivitiComponent"
        :model-id="model.id"
        :user-id="userId"
        @startOk="startOk"
        @formLoadSuccess="formLoadSuccess"
        :submit-act="instanceApi.userStartAct"
        :form-btn="false"></start-activiti-component>
    <span slot="footer" class="dialog-footer">
     <el-button @click="dialogVisible = false">取 消</el-button>
     <el-button @click="reststartActivitiComponent">清 空</el-button>
      <el-button type="primary" @click="submit">提交</el-button>
  </span>
  </el-dialog>

</template>

<script>


import StartActivitiComponent from "@/views/start/activiti/components/startActivitiComponent";
import instanceApi from "@/api/start/activiti/instanceApi";

export default {
  name: "startDialog",
  components: {StartActivitiComponent},
  data() {
    return {
      instanceApi,
      dialogVisible: false,
      model: null,
      loading: true,
      userId:null,
    }
  },
  created() {
    this.$store.dispatch("GetUserInfo").then(res => {
       this.userId=res.userInfo.id
    })
  },
  methods: {
    startOk() {
      this.dialogVisible = false;
    },
    show(model) {
      this.model = model;
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.startActivitiComponent.init();
      })
    },
    formLoadSuccess() {
      this.loading = false;
    },
    reststartActivitiComponent() {
      this.$refs.startActivitiComponent.resetForm();
    },
    handleClose() {
      console.log("对话框关闭")
      this.$refs.startActivitiComponent.resetForm();
      this.model = null;
      this.dialogVisible = false;
      this.loading = true
    },
    submit() {
      this.$refs.startActivitiComponent.submit();
    }
  }
}
</script>

<style scoped>

</style>
